package com.jfinal.generator;

import com.jfinal.generator.controller.GeneratorController;
import com.jfinal.generator.html.GeneratorHtml;
import com.jfinal.generator.model.GeneratorModel;
import com.jfinal.generator.service.GeneratorService;

//分成四部分代码生成工具，更加灵活 (建议model与service一对一匹配,controller灵活调整)
public class CodeGenerator {


    // 自动生成model
    public static void main(String[] args) {
        String sql_url = "jdbc:mysql://192.168.0.129:1291/dsfa_wljwrh?zeroDateTimeBehavior=CONVERT_TO_NULL&serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&useOldAliasMetadataBehavior=true&useSSL=false";
        String sql_username = "wljwrh";
        String sql_password = "Study_111111";

        // model 所使用的包名 (MappingKit 默认使用的包名)
        String modelPackageName = "com.dsfa.schedule.api.pojo.record.model";
        // 全表
        // new GeneratorModel(sql_url, sql_username, sql_password, modelPackageName).generate();
        // 指定表
        new GeneratorModel(sql_url, sql_username, sql_password, modelPackageName)
                .generate("schedule_record_relationship","schedule_record", "schedule_record_organization", "schedule_record_organization_group",
                        "schedule_record_organization_group_personnel", "schedule_record_detail");
    }

    // 自动生成service(可批量)
    public static void main2(String[] args) {
        String sql_url = "jdbc:mysql://IP:PORT/data";
        String sql_username = "username";
        String sql_password = "password";

        String modelPackageName = "com.lhm.data.model";
        String servicePackageName = "com.lhm.data.service";
        // 全表
        // new GeneratorService(sql_url, sql_username, sql_password,servicePackageName, modelPackageName).generate();
        // 指定表
        new GeneratorService(sql_url, sql_username, sql_password, servicePackageName, modelPackageName).generate("t_system_interface_type");
    }

    // 自动生成controller(只能单)
    public static void main3(String[] args) {
        String model = "com.lhm.data.model.TSystemInterfaceType";
        String bean = "interfaceType";
        String remark = "接口分类";
        // 实际路径/path/小写controller
        String path = "system";
        String controllerPackageName = "com.lhm.data.controller.admin.system";
        String servicePackageName = "com.lhm.data.service";
        // 单表
        new GeneratorController(bean, path, model, remark, controllerPackageName, servicePackageName).generate();
    }

    // 自动生成html(只能单)(生成查询query.html和编辑页面edit.html)(页面会比较丑仅供参考,请自行调整)
    public static void main4(String[] args) {
        String sql_url = "jdbc:mysql://IP:PORT/data";
        String sql_username = "username";
        String sql_password = "password";

        String bean = "interfaceType";
        // 输出路径在src/main/resources/webapp/+path路径
        String path = "system/interfacetype";
        String table = "t_system_interface_type";
        // 单表
        new GeneratorHtml(sql_url, sql_username, sql_password, bean, path, table).generate();
    }
}
